
export const getTableColumns = (params) => {
  // let columns = [
  //   { headerName: '设备ID', field: "machineId", minWidth: 60, flex: 1 },
  //   { headerName: '设备类型', field: "machineTypeId", minWidth: 60, flex: 1 },
  //   { headerName: '基准值', field: "rfctenDayAst", minWidth: 60, flex: 1 }
  // ]

  const columns = []
  let dataTime = ['设备ID', '设备类型', '基准值']

  // const temp = ['叠瓦线', '片花篮上', '印刷', '激光', '裂片机', '端子焊', '串花篮上']
  const temp = []

  params.forEach(item => {
    if(!dataTime.includes(item.dataTime.slice(5))){
      dataTime.push(item.dataTime.slice(5))
    }

    if(!temp.includes(item.machineTypeId)){
      temp.push(item.machineTypeId)
    }
  })

  const tableData = []
  temp.forEach((val) => {
    let obj = {}
    params.forEach((item) => {
      if(item.machineTypeId === val){

        obj.machineId = item.machineId
        obj.machineTypeId = item.machineTypeId
        obj.rfctenDayAst = item.rfctenDayAst
        obj[item.dataTime.slice(5)] = item.tenDayAst

      }
    })
    tableData.push(obj)
  })

  dataTime.forEach((item) => {
    if(item === '设备ID'){
      columns.push({ headerName: '设备ID', field: "machineId", minWidth: 100, flex: 1 })
    } else if (item === '设备类型') {
      columns.push({ headerName: '设备类型', field: "machineTypeId", minWidth: 80, flex: 1 })
    } else if (item === '基准值') {
      columns.push({ headerName: '基准值', field: "rfctenDayAst", minWidth: 50, flex: 1 })
    } else {
      columns.push({ headerName: item, field: item, minWidth: 40, flex: 1 })
    }

  })

  // const fieldOptions = ['oneDayAst', 'tenDayAst', 'baseTT', 'diftenDayAst']
  // let target = []
  // params = [{}, ...params]

  return {
    columns,
    target: tableData
  }
}
